<?php

namespace app\common\model;

use think\Model;
use think\Request;

/**
 * 会员余额日志模型
 */
class ReqRecord Extends Model
{

    // 表名
    protected $name = 'api_req_record';
    // 开启自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';
    // 定义时间戳字段名
    protected $createTime = 'create_time';
    protected $updateTime = '';
    // 追加属性
    protected $append = [
    ];

    /**
     * 记录接口请求信息
     * @param Request $request
     * @return $this
     */
    public static function insertReqInfo(Request $request)
    {
        return self::create(
            [
                'route_type' => $request->route('type'),
                'req_time' => $request->server('REQUEST_TIME'),
                'req_url' => strtolower($request->module() . '/' . $request->controller() . '/' . $request->action()),
                'req_params' => json_encode($request->param()),
                'req_ip' => $request->ip(),
            ]
        );
    }
}
